'use strict';

const {
	Controller
} = require('uni-cloud-router');

const { wxapi } = require('use-api');

const dbcmd = uniCloud.database().command;

module.exports = class TestController extends Controller {
	// 企业付款到零钱
	async transfers() {
		let response = {
			code: 1,
			datas: null,
			msg: ''
		};

		const url = 'https://tcb-123-887c2d.service.tcloudbase.com/agent/wxpay-transfers';

		let start = Date.now();

		const res = await this.curl(url, {
			nestedQuerystring: true,
			method: 'post',
			headers: {
				'Content-Type': 'application/json',
				'use-token': '110'
			},
			dataType: 'json',
			data: {
				trade_no: '123',
				openid: '123',
				truename: '123',
				amount: '123',
				desc: '123'
			}
		});

		response.datas = res.data;

		let end = Date.now();
		response.code = 0;
		response.msg = `耗时：${end - start}ms`;
		return response;
	}
	
	// 微信公众号Token
	async h5WeixinToken() {
		return await wxapi.get_token();
	}
}
